﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
//
public class Example1 : MonoBehaviour
{

    public string prefabRef;

    List<AsyncOperationHandle> objHandles = new List<AsyncOperationHandle>();
    private void OnGUI()
    {
        if (GUILayout.Button("InstantiateAsync"))
        {
            var handle = Addressables.InstantiateAsync(prefabRef);
            handle.Completed += e =>
            {
                Debug.LogError("实例化：" + e.Result.name);
            };
            objHandles.Add(handle);
        }
        if (GUILayout.Button("ReleaseInstance"))
        {
            if (objHandles.Count > 0)
            {
                var handle = objHandles[0];
                Addressables.ReleaseInstance(handle);
                objHandles.RemoveAt(0);
            }
        }

        
        
    }

}
